const fs = require('fs').promises;
const path = require('path');

const readUserData = async() => {
    let userdata = [];
    try {
        const result = await fs.readFile(path.resolve(__dirname, '../', 'mock/user.json'),'utf-8');
        userdata = JSON.parse(result);
    } catch (error) {
        console.log(error);
    }
    return userdata;
};

const writeUserData = async(data) => {
    let success = false;
    try {   
        await fs.writeFile(path.resolve(__dirname, '../', 'mock/user.json'), data, 'utf-8');
        success = true;
    } catch (error) {   
        console.log(error);
    }
    return false;
};

module.exports = {
    readUserData,
    writeUserData,
};
